package com.mew.common.vo;

import cn.hutool.core.util.RandomUtil;
import com.mew.common.config.NicknameUtil;
import com.mew.common.enm.UserType;
import com.mew.common.rest.bo.GameSession;
import com.mew.common.util.NumberUtil;
import com.mew.common.util.RandomIdUtil;
import com.zebra.common.ByteBufUtils;
import io.netty.buffer.ByteBuf;
import lombok.Data;
import lombok.ToString;

@Data
@ToString
public class UserSessionVO{
    public int userType;

    public GameSession gameSession;

    public int playTimes;

    public void write(ByteBuf b){
        ByteBufUtils.writeLong(b,gameSession.getUserId());
        ByteBufUtils.writeString(b,gameSession.getNickname());
        ByteBufUtils.writeInt(b,gameSession.getHeadPath());
        ByteBufUtils.writeLong(b,gameSession.getGoldNumber());
    }

    public void read(ByteBuf b) {
        setUserId(ByteBufUtils.readLong(b));
        setHeadPath(ByteBufUtils.readInt(b));
    }

    public UserSessionVO buildRobotUserMessage(int min, String scope){
        this.gameSession = new GameSession();
        min = min == 0 ? 1230 : min;
        long v = (long) (Math.random() * min);
        long goldNumber = min *  NumberUtil.randomIntByStr(scope, "-")+ v;
        this.setUserId(RandomIdUtil.getUserId());
        this.setGid(RandomIdUtil.getGid(0, 8));
        this.setNickname(NicknameUtil.getName());
        this.setHeadPath(RandomUtil.randomInt(1, 10));
        this.setUserType(UserType.Robot.code());
        this.setGoldNumber(goldNumber);
        return this;
    }

    public long updateGoldNumber(long betNumber, long paymentNumber){
        return  this.gameSession.updateGoldNumber(betNumber, paymentNumber);
    }

    public void updateGoldNumber(long goldNumber){
        this.gameSession.updateGoldNumber(goldNumber);
    }

    public long getUserId() {
        return gameSession.getUserId();
    }

    public void setUserId(long userId) {
        this.getGameSession().setUserId(userId);
    }

    public int getGameId() {
        return gameSession.getGameId();
    }

    public void setGameId(int gameId) {
        this.getGameSession().setGameId(gameId);
    }

    public int getRoomId() {
        return getGameSession().getRoomId();
    }

    public void setRoomId(int roomId) {
        this.getGameSession().setRoomId(roomId);
    }

    public int getTableId() {
        return gameSession.getTableId();
    }

    public void setTableId(int tableId) {
        this.getGameSession().setTableId(tableId);
    }

    public int getSeatNo() {
        return getGameSession().getSeatNo();
    }

    public void setSeatNo(int seatNo) {
        this.getGameSession().setSeatNo(seatNo);
    }

    public String getRoomBetArray() {
        return getGameSession().getRoomBetArray();
    }

    public void setRoomBetArray(String roomBetArray) {
        this.getGameSession().setRoomBetArray(roomBetArray);
    }

    public String getGid() {
        return getGameSession().getGid();
    }

    public void setGid(String gid) {
        this.getGameSession().setGid(gid);
    }

    public String getNickname() {
        return getGameSession().getNickname();
    }

    public void setNickname(String nickname) {
        this.getGameSession().setNickname(nickname);
    }

    public int getHeadPath() {
        return getGameSession().getHeadPath();
    }

    public void setHeadPath(int headPath) {
        this.getGameSession().setHeadPath(headPath);
    }

    public long getGoldNumber() {
        return getGameSession().getGoldNumber();
    }

    public void setGoldNumber(long goldNumber) {
        this.getGameSession().setGoldNumber(goldNumber);
    }

    public long getInoutId() {
        return getGameSession().getInoutId();
    }

}
